/* Copyright 2009
 *
 * This program and the accompanying materials
 * are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * Contributors:
 * 	   IBM Corporation - initial API and implementation for JDT/DLTK
 *     Sean W. Quinn - initial adoption for use with PHP from various sources.
 */
package org.eclipse.php.internal.ui.preferences.formatter.tab;

import java.net.URL;

import org.eclipse.dltk.ui.formatter.IFormatterModifyDialog;
import org.eclipse.dltk.ui.util.SWTFactory;
import org.eclipse.php.core.formatter.PHPCodeFormatterConstants;
import org.eclipse.php.internal.ui.preferences.formatter.PHPFormatterControlManager;
import org.eclipse.php.internal.ui.preferences.formatter.PHPFormatterMessages;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;

/**
 * @author Sean W. Quinn (swquinn@gmail.com)
 */
public class PHPCodeFormatterNewLinesTabPage extends PHPCodeFormatterTabPage {

	/**
	 * @param dialog
	 */
	public PHPCodeFormatterNewLinesTabPage(final IFormatterModifyDialog dialog) {
		super(dialog);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	@Override
	protected void doCreateOptions(final PHPFormatterControlManager manager, final Composite parent) {
		createInsertNewLineGroup(manager, parent);
		createArrayInitializerNewLineGroup(manager, parent);
		createEmptyStatementNewLineGroup(manager, parent);
		// createAnnotationNewLineGroup(manager, parent); // Annotations not supported for PHP
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createInsertNewLineGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.NewLinesTabPage_newlines_group_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_TYPE_DECLARATION,
				PHPFormatterMessages.NewLinesTabPage_newlines_group_option_empty_class_body, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ANONYMOUS_TYPE_DECLARATION,
				PHPFormatterMessages.NewLinesTabPage_newlines_group_option_empty_anonymous_class_body, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_METHOD_BODY,
				PHPFormatterMessages.NewLinesTabPage_newlines_group_option_empty_method_body, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_BLOCK,
				PHPFormatterMessages.NewLinesTabPage_newlines_group_option_empty_block, COLUMN_SPAN);

		// **
		//manager.createCheckbox(group,
		//		DefaultPHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ENUM_DECLARATION,
		//		PHPFormatterMessages.NewLinesTabPage_newlines_group_option_empty_enum_declaration, COLUMN_SPAN);

		// **
		//manager.createCheckbox(group,
		//		DefaultPHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ENUM_CONSTANT,
		//		PHPFormatterMessages.NewLinesTabPage_newlines_group_option_empty_enum_constant, COLUMN_SPAN);

		// **
		//manager.createCheckbox(group,
		//		DefaultPHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_IN_EMPTY_ANNOTATION_DECLARATION,
		//		PHPFormatterMessages.NewLinesTabPage_newlines_group_option_empty_annotation_decl_body, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AT_END_OF_FILE_IF_MISSING,
				PHPFormatterMessages.NewLinesTabPage_newlines_group_option_empty_end_of_file, COLUMN_SPAN);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createArrayInitializerNewLineGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.NewLinesTabPage_arrayInitializer_group_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER,
				PHPFormatterMessages.NewLinesTabPage_array_group_option_after_opening_brace_of_array_initializer, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_BEFORE_CLOSING_BRACE_IN_ARRAY_INITIALIZER,
				PHPFormatterMessages.NewLinesTabPage_array_group_option_before_closing_brace_of_array_initializer, COLUMN_SPAN);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createEmptyStatementNewLineGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.NewLinesTabPage_empty_statement_group_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE,
				PHPFormatterMessages.NewLinesTabPage_emtpy_statement_group_option_empty_statement_on_new_line, COLUMN_SPAN);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createAnnotationNewLineGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.NewLinesTabPage_annotations_group_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_MEMBER,
				PHPFormatterMessages.NewLinesTabPage_annotations_group_members, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_PARAMETER,
				PHPFormatterMessages.NewLinesTabPage_annotations_group_paramters, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_INSERT_NEW_LINE_AFTER_ANNOTATION_ON_LOCAL_VARIABLE,
				PHPFormatterMessages.NewLinesTabPage_annotations_group_local_variables, COLUMN_SPAN);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected URL getPreviewContent() {
		return getClass().getResource("bracesPreview.php"); //$NON-NLS-1$
	}
}
